package com.lishe.lishe.lishe.bean;

import android.util.Log;

import com.lishe.lishe.lishe.common.LogDog;

import org.json.JSONObject;

import java.io.Serializable;
import java.util.LinkedList;

/**
 * Created by lwa on 2017/8/14.
 * 商铺对象
 */

public class BusinessObject extends OrderObject implements Serializable {

    /**
     * 订单状态 0-全部，1-待付款，2-待发货，3-待收货，4-退换货
     */
    private int businessType = 0;
    /**
     * 订单状态 0-全部，1-待付款，2-待发货，3-待收货，4-退换货
     */
    private String businessStatus;
    /**
     * 商铺id
     */
    private String businessId;
    /**
     * 商铺中购买商品的总金额
     */
    private double businessPayMoney = 0;
    /**
     * 商铺订单支付id相当于tid
     */
    private String businessPaymentId;

    /**
     * 订单名称
     */
    private String businessShopName;
    /**
     * 商品邮费
     */
    private double businessPostFee;
    /**
     * 商品邮费
     */
    private double payment;

    /**
     * 店铺下的商品
     */
    private LinkedList<GoodObject> lisGoogsObjects = new LinkedList();

    /**
     * 店铺描述
     */
    private String businessDescribe;
    /**
     * 店铺备注
     */
    private String businessNote;
    /**
     * 商铺订单id（）
     */
    private String tid;
    /**
     * //全选该店铺为true，只选一个或不选则为false
     */
    private boolean isCheck = false;
    /**
     * 店铺下，选中的商品数
     */
    private int checkGoodsCount = 0;


    public int getBusinessType() {
        return businessType;
    }

    public void setBusinessType(int businessType) {
        this.businessType = businessType;
    }

    public String getBusinessId() {
        return businessId;
    }

    public void setBusinessId(String businessId) {
        this.businessId = businessId;
    }

    public double getBusinessPayMoney() {
        businessPayMoney = 0;
        for (GoodObject goodObject : lisGoogsObjects) {
            if (goodObject.isCheck()) {
                businessPayMoney = businessPayMoney + (goodObject.getGoodsPrice() * goodObject.getGoodsCount());
            }
        }
        return businessPayMoney;
    }

//    public void setBusinessPayMoney(double businessPayMoney) {
//        this.businessPayMoney = businessPayMoney;
//    }

    public String getBusinessShopName() {
        return businessShopName;
    }

    public void setBusinessShopName(String businessShopName) {
        this.businessShopName = businessShopName;
    }

    public double getBusinessPostFee() {
        return businessPostFee;
    }

    public void setBusinessPostFee(double businessPostFee) {
        this.businessPostFee = businessPostFee;
    }

    public LinkedList<GoodObject> getLisGoogsObjects() {
        return lisGoogsObjects;
    }

    public void setLisGoogsObjects(LinkedList<GoodObject> lisGoogsObjects) {
        this.lisGoogsObjects = lisGoogsObjects;
    }


    public String getBusinessStatus() {
        return businessStatus;
    }

    public void setBusinessStatus(String businessStatus) {
        this.businessStatus = businessStatus;
    }

    public String getBusinessPaymentId() {
        return businessPaymentId;
    }

    public void setBusinessPaymentId(String businessPaymentId) {
        this.businessPaymentId = businessPaymentId;
    }

    public String getBusinessDescribe() {
        return businessDescribe;
    }

    public void setBusinessDescribe(String businessDescribe) {
        this.businessDescribe = businessDescribe;
    }

    public String getBusinessNote() {
        return businessNote;
    }

    public void setBusinessNote(String businessNote) {
        this.businessNote = businessNote;
    }

    public String getTid() {
        return tid;
    }

    public void setTid(String tid) {
        this.tid = tid;
    }

    public boolean isCheck() {
        return isCheck;
    }

    public void setCheck(boolean check) {
        isCheck = check;
    }

    public int getCheckGoodsCount() {
        checkGoodsCount = 0;
        for (GoodObject goodObject : lisGoogsObjects) {
            if (goodObject.isCheck()) {
                checkGoodsCount = checkGoodsCount + 1;
            }
        }
        return checkGoodsCount;
    }

//    public void setCheckGoodsCount(int checkGoodsCount) {
//        this.checkGoodsCount = checkGoodsCount;
//    }

    public String getStatusString() {
        if (businessStatus.equals("WAIT_BUYER_PAY")) {
//            return "待付款";
            return "待付款";
        }
        if (businessStatus.equals("TRADE_CLOSED_BY_USER") || businessStatus.equals("TRADE_CLOSED_BY_SYSTEM") || businessStatus.equals("TRADE_CLOSED_BY_ADMIN")) {
            return "已取消";
        }
        if (businessStatus.equals("WAIT_SELLER_SEND_GOODS")) {
//            return "待发货";
            return "已付款";
        }
        if (businessStatus.equals("WAIT_BUYER_CONFIRM_GOODS")) {
//            return "待收货";
            return "卖家已发货";
        }
        if (businessStatus.equals("TRADE_FINISHED")) {
//            return "已完成";
            return "交易成功";
        }
        if (businessStatus.equals("IN_STOCK")) {
            return "备货中";
        }
        if (businessStatus.equals("WAIT_COMMENT")) {
            return "待评论";
        }
        return "退换货";//都不符合的情况返回退货
    }

    /**
     * 店铺消费金额
     *
     * @return
     */
    public double getBusinessTotalMoney() {
        double money = 0;
        for (int i = 0; i < lisGoogsObjects.size(); i++) {
            GoodObject goods = lisGoogsObjects.get(i);
            money = money + goods.getGoodsCount() * goods.getGoodsPrice() + businessPostFee;
        }
        return money;
    }


    public double getPayment() {
        return payment;
    }

    public void setPayment(double payment) {
        this.payment = payment;
    }

    public void opsJson(BusinessObject businessObject, JSONObject jsonObject) {
        businessObject.setPayment(jsonObject.optDouble("payment"));
        businessObject.setBusinessPaymentId(jsonObject.optString("payment_id"));
        businessObject.setBusinessId(jsonObject.optString("tid"));
        businessObject.setTid(jsonObject.optString("tid"));
        JSONObject tradeData = jsonObject.optJSONObject("TradeData");
        businessObject.setBusinessStatus(tradeData.optString("status"));
        businessObject.setBusinessPostFee(tradeData.optDouble("post_fee"));
        businessObject.setBusinessShopName(tradeData.optString("shopName"));
    }

    /**
     * 复制已经知道的类
     */
    public void copy(BusinessObject object){
        setBusinessShopName(object.getBusinessShopName());
        setCheck(object.isCheck);
        setBusinessDescribe(object.getBusinessDescribe());
        setBusinessId(object.getBusinessId());
        setBusinessNote(object.getBusinessNote());
        setBusinessPaymentId(object.getBusinessPaymentId());
        setBusinessPostFee(object.getBusinessPostFee());
        setBusinessStatus(object.getBusinessStatus());
        setBusinessType(object.getBusinessType());//13
        setTid(object.getTid());
        getLisGoogsObjects().addAll(object.getLisGoogsObjects());
        setPayment(object.getPayment());
    }
}

